package com.hzncc.flowable_diboot.contract.delegate;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hzncc.flowable_diboot.contract.entity.ContractAudit;
import com.hzncc.flowable_diboot.contract.service.ContractAuditService;
import com.hzncc.flowable_diboot.contract.vo.ContractAuditVO;
import com.hzncc.flowable_diboot.enums.ContractAuditStatusEnum;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * @Description :
 * @Date : 2024/7/22
 * @Author : ChenJin
 * @Version : v1.0.0
 **/
@Service
public class SapDelegate implements JavaDelegate {
    
    @Resource
    private ContractAuditService contractAuditService;
    
    @Override
    public void execute(DelegateExecution delegateExecution) {
        //当前正在执行任务对应的流程实例
        String instanceId = delegateExecution.getProcessInstanceId();
        LambdaQueryWrapper<ContractAudit> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ContractAudit::getInstanceId,instanceId).eq(ContractAudit::isDeleted,0);
        ContractAudit contractAudit = contractAuditService.getSingleEntity(queryWrapper);
        ContractAuditVO contractDetail = contractAuditService.getContractDetail(contractAudit.getId());
        // 请求封装
        
        // 推送SAP
        
        // 推送完成后，获取响应结果，变更合同审批状态
        contractAudit.setContractStatus(ContractAuditStatusEnum.SAP_PROCESSING.getCode())
                .setSapStatus("1").setSapMsg("");
        contractAuditService.updateEntity(contractAudit);
    }
}
